package memento;

/**
 * Created by longshihan on 2017/7/3.
 * 备忘录模式
 */
public class MainClass {

    public static void main(String args[]) {

        Person per = new Person("lifeng", "男", 30);

        //保存内部状态
        Person backup = new Person();
        backup.setName(per.getName());
        backup.setAge(per.getAge());
        backup.setSex(per.getSex());

        per.display();

        //修改
        per.setAge(20);
        per.display();
        //回滚 还原
        per.setName(backup.getName());
        per.setSex(backup.getSex());
        per.setAge(backup.getAge());

        per.display();

        //memento

        Memento memento = per.createMemento();

        per.setName("beifeng");
        per.setSex("女");
        per.setAge(1);

        per.display();

        per.setMemento(memento);
        per.display();

        //管理者

        Caretaker caretaker=new Caretaker();
        caretaker.setMemento(per.createMemento());

        per.setName("beifeng");
        per.setSex("女");
        per.setAge(1);

        per.display();

        per.setMemento(caretaker.getMemento());
        per.display();
    }
}
